TARGET=libutils.a

source_dirs  = ./src
CC = g++
AR = ar

CFLAGS       = -g3 -ggdb -Wall -Werror 
DEFLIST      = -DUNIX -DLINUX -DPTHREADS -DMULTITHREAD -D_REENTRANT

IPATHS       = -I. -I./include -I/usr/include/ -I../tinyxml/include -I../tinyxpath/include


LPATHS       = -L. -L./lib -L/usr/lib -L../tinyxpath/include -L../tinyxml/include


LIBS         = -lpthread -lm -lrt -ltinyxpath -ltinyxml -lboost_date_time


VPATH   := $(source_dirs)

search_wildcard := $(addsuffix /*.cpp,$(source_dirs))

all: $(TARGET)

$(TARGET): $(notdir $(patsubst   %.cpp,%.o,$(wildcard   $(search_wildcard)))) $(LIBRARIES)
	@echo Linking $@
	@$(AR) -cr $@ $^

%.o: %.cpp
	@echo Compiling $<
	@$(CC) $(CFLAGS) $(DEFLIST) $(IPATHS) $(LFLAGS) -c -MD $(addprefix -I ,$(source_dirs)) $<

ifneq "$(wildcard *.d)" ""
include $(wildcard *.d)
endif

clean: doc_clean
	rm  -f *.o
	rm  -f *.d
	rm  -f $(TARGET)

# Documentation
DOC_DIR = docs
DOXYFILE = Doxyfile
DOXYLOG = Doxygen.log
DOXY_TARGET = $(DOC_DIR)/html/index.html
DOC_DOXYFILE = $(DOC_DIR)/$(DOXYFILE)
DOXY_DEP = $(wildcard $(patsubst %, %/*.cpp, $(source_dirs) ) ) $(wildcard $(patsubst %, %/*.h, $(include_dirs) ) )

$(DOC_DIR):	
	@echo "Creating docs dir ..."
	@mkdir $(DOC_DIR)

$(DOC_DOXYFILE): $(DOC_DIR) $(DOXYFILE)
	@echo "Copying Doxy file ..."
	@cp $(DOXYFILE) $(DOC_DIR)

$(DOXY_TARGET): $(DOC_DOXYFILE) $(DOXY_DEP)
	@echo "Generating Doxygen documentation ($(DOXY_TARGET)) ..."
	@cd $(DOC_DIR) && doxygen $(DOXYFILE)

doc:	$(DOXY_TARGET)
	@echo "Updating result."
	@cd $(DOC_DIR) && rm -f index.html && ln -s html/index.html index.html
	@touch $(DOC_DOXYFILE)
	@touch $(DOXY_TARGET)

doc_clean:
	@echo "Removing documentation ..."
	rm -rf $(DOC_DIR)

